﻿using System;
using System.ComponentModel;
using GalaSoft.MvvmLight.Command;
using System.Windows.Media;

namespace Rio.Framework.Pages.Controls.Models
{
    public interface ISelectableItem<T> : INotifyPropertyChanged
    {
        bool IsSelected { get; set; }
        string Text { get; set; }
        T Value { get; set; }
        Color Color { get; set; }
    }

    public class SelectableItemViewModel<T> : ISelectableItem<T>
    {

        #region Attributs

        private bool _isSelected;
        private string _text;
        private T _value;
        private Color _color;

        #endregion

        #region Events

        public event PropertyChangedEventHandler PropertyChanged;
        private void RaisePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion Events

        #region Properties


        /// <summary>
        /// Gets or sets the is selected.
        /// </summary>
        /// <value>The is selected.</value>
        public bool IsSelected
        {
            get
            {
                return _isSelected;
            }
            set
            {
                _isSelected = value;
                RaisePropertyChanged("IsSelected");
            }
        }

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        /// <value>The text.</value>
        public string Text
        {
            get
            {
                return _text;
            }
            set
            {
                _text = value;
                RaisePropertyChanged("Text");
            }
        }

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public T Value
        {
            get
            {
                return _value;
            }
            set
            {
                _value = value;
                RaisePropertyChanged("Value");
            }
        }

        /// <summary>
        /// Gets or sets the color.
        /// </summary>
        /// <value>The color.</value>
        public Color Color
        {
            get
            {
                return _color;
            }
            set
            {
                _color = value;
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="SelectableItemViewModel" /> class.
        /// </summary>
        public SelectableItemViewModel()
        {
        }

        /// <summary>
        /// Initializes a new instance of the SelectableItemViewModel class.
        /// </summary>
        /// <param name="isSelected">The is selected.</param>
        /// <param name="text">The text.</param>
        /// <param name="value">The value.</param>
        public SelectableItemViewModel(bool isSelected, string text, T value)
            :this()
        {
            _isSelected = isSelected;
            _text = text;
            _value = value;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SelectableItemViewModel" /> class.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="value">The value.</param>
        public SelectableItemViewModel(string text, T value)
        : this(false, text, value)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SelectableItemViewModel" /> class.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="value">The value.</param>
        /// <param name="color">The color.</param>
        public SelectableItemViewModel(string text, T value, Color color)
        : this(false, text, value)
        {
            this.Color = color;
        }

        #endregion


        public override string ToString()
        {
            return Text;
        }
    }
}
